package io.github.cubelitblade.librarymanagementbackend.controller;

import io.github.cubelitblade.librarymanagementbackend.service.UserBorrowFacade;
import io.github.cubelitblade.librarymanagementbackend.service.UserFavoriteFacade;
import io.github.cubelitblade.librarymanagementbackend.service.UserService;
import io.github.cubelitblade.librarymanagementbackend.utils.ResultContext;
import io.github.cubelitblade.librarymanagementbackend.vo.BorrowResponseVO;
import io.github.cubelitblade.librarymanagementbackend.vo.FavoriteResponseVO;
import io.github.cubelitblade.librarymanagementbackend.vo.UserVO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/users")
public class UserController {
    private final UserService userService;
    private final UserBorrowFacade userBorrowFacade;
    private final UserFavoriteFacade userFavoriteFacade;

    public UserController(UserService userService, UserBorrowFacade userBorrowFacade, UserFavoriteFacade userFavoriteFacade) {
        this.userService = userService;
        this.userBorrowFacade = userBorrowFacade;
        this.userFavoriteFacade = userFavoriteFacade;
    }

    @GetMapping("/{id}")
    public ResponseEntity<ResultContext<UserVO>> getUser(@PathVariable Integer id) {
        return ResponseEntity.ok(ResultContext.succeed(userService.getUser(id)));
    }

    @GetMapping("/{id}/borrows")
    public ResponseEntity<ResultContext<List<BorrowResponseVO>>> listBorrowsByUser(@PathVariable Integer id) {
        return ResponseEntity.ok(ResultContext.succeed(userBorrowFacade.listBorrowsByUser(id)));
    }

    @GetMapping("/{id}/favorites")
    public ResponseEntity<ResultContext<List<FavoriteResponseVO>>> listFavorites(@PathVariable Integer id) {
        return ResponseEntity.ok(ResultContext.succeed(userFavoriteFacade.listFavorites(id)));
    }
}
